package com.example.demo.behavior.strategy;

import lombok.AllArgsConstructor;
import lombok.Data;

/**
 * @Desc:
 * @Author zzz
 * @Date 2021/2/20
 * @Version V1.0
 */
@Data
@AllArgsConstructor
public class StrategyTest {

    Payment payment;

    public StrategyTest() {
    }

    void buyGoods(String goodsName, Payment payment) {
        System.out.println("buy " + goodsName);
        payment.pay();
    }

    void buyGoods(String goodsName, String payWay) {
        System.out.println("buy " + goodsName);
        /*if ("Alipay".equals(payWay)) {
            this.payment = new AliPay();
        } else if ("WeChat".equals(payWay)) {
            this.payment = new WeChatPay();
        } else if ("YinLian".equals(payWay)) {
            this.payment = new YinLianPay();
        }*/
        // senior way
        this.payment = PaymentEnum.load(payWay);
        payment.pay();
    }

    public static void main(String[] args) {
        StrategyTest test1 = new StrategyTest();
        test1.buyGoods("phone", new AliPay());
        test1.buyGoods("computer", new WeChatPay());
        test1.buyGoods("book", new YinLianPay());

        test1.buyGoods("milk", "Alipay");
    }

}
